<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Reserve;
use App\Models\User;
use Illuminate\Support\Facades\Hash;

class SingnInController extends Controller
{
    //
    public function __construct(Request $request){

    }

    public function SingnIn(Request $request){
        $reserve = new Reserve();
        $reserve_data = $reserve -> where([['invitation_code', $request->invitation_code],['status', '1']])->first();
        if($reserve_data){
            if(Hash::check($request->password, $reserve_data->user->password)){
                $reserve_data->status = '2';
                $reserve_data->save();
                return $this->ReturnSuccess('Singn In success');
            }else{
                return $this->ReturnError('Singn In failed', ['error' => 'Invalid password']);
            }
        }else{
             return $this->ReturnError('Singn In failed', ['error' => 'Invalid invitation code']);
        }
    }
}
